package exercise;

import study.FileTreatementException;

public abstract class Entry {

    protected Entry parent;

    public abstract String getName();

    public abstract int getSize();

    public void printList(){
        printList("");
    }

    public abstract void printList(String prefix);

    public void getPath(){
        String path = path(this, "");
        System.out.println(path);
    }

    private String path(Entry entry, String result){
        String name = entry.getName();
        Entry thisParent = entry.parent;

        if(thisParent == null){
            return "/" + name + result;
        }

        return path(thisParent, "/" + name + result);
    }

    protected Entry add(Entry entry) throws FileTreatementException{
        throw new FileTreatementException();
    }

    @Override
    public String toString(){
        return getName() + ":" + getSize();
    }
}
